package com.example.web;

import com.example.domain.Student;
import com.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/provider")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @Value("${server.port}")
    private String port;

    @RequestMapping("/findAll")
    public List<Student> findAllStudent(){
        return studentService.findAllStudent();
    }

    @GetMapping("/findById/{id}")
    public Student findStudentById(@PathVariable("id") Long id){
        return studentService.findStudentById(id);
    }

    @PostMapping("/save")
    public Student saveStudent(@RequestBody Student student){
        return studentService.saveOrUpdateStudent(student);
    }

    @PutMapping("/update")
    public Student updateStudent(@RequestBody Student student){
        return studentService.saveOrUpdateStudent(student);
    }

    @DeleteMapping("/deleteById/{id}")
    public Boolean deleteStudentById(@PathVariable("id") Long id){
        return studentService.deleteStudentById(id);
    }

    @RequestMapping("/index")
    public String index(){
        return "port: "+port;
    }
}
